import Icon from '@/components/Icon';
import { useHistory } from 'react-router-dom';
import styles from './index.module.scss';
import classNames from 'classnames';

interface INavBarProps {
  onClick?: () => void;
  children?: React.ReactNode;
  right?: React.ReactNode;
  fixed?: boolean;
}

export default function NavBar({ onClick, children, right, fixed }: INavBarProps) {
  const history = useHistory();
  const handleBack = () => {
    onClick ? onClick() : history.goBack();
  };
  return (
    <div className={styles.root}>
      <div className={classNames('main', { fixed })}>
        <div className="left">
          <Icon type="iconfanhui" onClick={handleBack} />
        </div>
        <div className="title">{children}</div>
        <div className="right">{right}</div>
      </div>
    </div>
  );
}
